package com.qimou.iems.service.impl;

import com.qimou.iems.entity.PageArgs;
import com.qimou.iems.entity.PageList;
import com.qimou.iems.entity.QualityItem;
import com.qimou.iems.mapper.IQualityItemMapper;
import com.qimou.iems.service.IQualityItemService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Qimou Xie
 * @date 2018/6/9 14:44.
 **/

@Service
public class QualityItemServiceImpl implements IQualityItemService {

    @Resource
    private IQualityItemMapper qualityItemMapper;

    @Override
    public void save(QualityItem item) {
        qualityItemMapper.insert(item);
    }


    @Override
    public QualityItem findById(Integer id) {
        return qualityItemMapper.selectById(id);
    }

    @Override
    public void update(QualityItem item) {
        qualityItemMapper.update(item);
    }

    @Override
    public List<QualityItem> findAll() {
        return qualityItemMapper.selectAll();
    }

    @Override
    public PageList<QualityItem> findList(Map<String, Object> map, PageArgs pageArgs) {

        List<QualityItem> qualityItems = new ArrayList<QualityItem>();
        Integer count = qualityItemMapper.countQualityItem(map);
        if(null != count && count > 0){
            map.put("pageArgs",pageArgs);
            qualityItems = qualityItemMapper.selectQualityItem(map);
        }
        return new PageList<QualityItem>(qualityItems,count);
    }


    @Override
    public List<QualityItem> findQualityList(Integer childId) {
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("pageArgs",null);
        map.put("childCategoryId",childId);
        map.put("qualityName",null);
        return qualityItemMapper.selectQualityItem(map);
    }
}
